package com.sat.client.adapter

import android.content.Context
import android.view.ViewGroup
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.sat.client.R
import com.sat.client.bean.DeviceInfo

class DevicesAdapter : BaseQuickAdapter<DeviceInfo, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: DeviceInfo?) {
        item?.run {
            holder.getView<TextView>(R.id.tv_device_model).text =
                "${context.getString(R.string.model)}:${model}"
            holder.getView<TextView>(R.id.tv_ser_no).text =
                "${context.getString(R.string.serNo)}:${serNo}"
            holder.getView<TextView>(R.id.tv_ip).text = "${context.getString(R.string.ip)}:${ip}"
            when (model) {
                "GF5000" -> {
                    holder.setImageResource(R.id.iv_device, R.drawable.img_gf5000)
                }

                "D320" -> {
                    holder.setImageResource(R.id.iv_device, R.drawable.img_d320)
                }

                else -> {

                }
            }
        }

    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.layout_device_item, parent)
    }
}